package com.mysoft.gfyx.common.rpc.opensearch.dto;

import com.google.common.base.Joiner;
import com.mysoft.framework.common.exception.BusinessLogicException;
import lombok.Data;

import java.util.ArrayList;

@Data
public class SearchMohurdProjectRequestDto extends SearchBaseRequestDto {
    private String keyword;
    private String province_code;
    private String city_code;
    private String company_type;
    /**
     * 建筑性质
     */
    private String prj_property_num;
    /**
     * 工程用途
     */
    private String prj_function_num;
    /**
     * 高端项目
     */
    private String is_price_gt_avg;
    /**
     * 项目分类
     */
    private String prj_type_num;

    private String all_invest_start;
    private String all_invest_end;
    private String prj_approval_date_start;
    private String prj_approval_date_end;
    private String tender_result_date_start;
    private String tender_result_date_end;
    private String contract_date_start;
    private String contract_date_end;
    private String begin_date_start;
    private String begin_date_end;
    private String end_date_start;
    private String end_date_end;
    private String update_time_start;
    private String update_time_end;
    private String area;
    private String created_time;

    private String developer_top_100_label;
    private String new_area_expand_label;
    private String new_decorate_expand_label;
    private String new_land_usage_expand_label;
    private String price_gt_avg_label;

    private int page = 1;
    private int page_size;

    protected void setFilterByField(String field, String operatorType, Object value) {
        switch (field) {
            case "build_corp_name":
            case "prj_name":
                if (value != null) {
                    this.setKeyword(value.toString());
                }
                break;
            case "all_invest":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setAll_invest_start(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setAll_invest_end(value.toString());
                }
                break;
            case "prj_approval_date":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setPrj_approval_date_start(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setPrj_approval_date_end(value.toString());
                }
                break;
            case "tender_result_date":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setTender_result_date_start(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setTender_result_date_end(value.toString());
                }
                break;
            case "contract_date":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setContract_date_start(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setContract_date_end(value.toString());
                }
                break;
            case "begin_date":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setBegin_date_start(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setBegin_date_end(value.toString());
                }
                break;
            case "end_date":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setEnd_date_start(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setEnd_date_end(value.toString());
                }
                break;
            case "update_time":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setUpdate_time_start(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setUpdate_time_end(value.toString());
                }
                break;
            case "company_type_label":
                if (operatorType.equals("in") && value instanceof ArrayList) {
                    String labels = Joiner.on(",").join(((ArrayList<?>) value));
                    this.setCompany_type(labels);
                }
                break;
            case "prj_type_num":
                if (operatorType.equals("in") && value instanceof ArrayList) {
                    String labels = Joiner.on(",").join(((ArrayList<?>) value));
                    this.setPrj_type_num(labels);
                }
                break;
            case "prj_property_num":
                if (operatorType.equals("in") && value instanceof ArrayList) {
                    String labels = Joiner.on(",").join(((ArrayList<?>) value));
                    this.setPrj_property_num(labels);
                }
                break;
            case "tags_set":
                if (value instanceof ArrayList<?>) {
                    for (Object tag : (ArrayList<?>) value) {
                        this.setTags(tag.toString());
                    }
                } else {
                    this.setTags(value.toString());
                }
                break;
            case "province_code":
                this.dynamicSetPropertyByOperation("province_code", operatorType, value);
                break;
            case "city_code":
                this.dynamicSetPropertyByOperation("city_code", operatorType, value);
                break;
            default:
                this.dynamicSetPropertyByOperation(field, operatorType, value);
        }
    }

    protected void setTags(String tags) {
        switch (tags) {
            case "developer_top_100_label":
                this.setDeveloper_top_100_label("地产百强");
                break;
            case "new_decorate_expand_label":
                this.setNew_decorate_expand_label("新精装客群");
                break;
            case "new_land_usage_expand_label":
                this.setNew_land_usage_expand_label("新住宅客群");
                break;
            case "new_area_expand_label":
                this.setNew_area_expand_label("新区域拓展");
                break;
            case "price_gt_avg_label":
                this.setPrice_gt_avg_label("高端项目客群");
                break;
            default:
                throw new BusinessLogicException("未定义的标签" + tags);
        }
    }
}
